/*查询数据*/
function homePagequery() {
    $.ajax({
        type: "POST",
        url: root.brandWebsite.query,
        cache: false,  //禁用缓存
        dataType: "json",
        contentType: "application/json",
        data: JSON.stringify({

        }),
        success: function (data) {
            if(data.errorCode==0){
                homePagelist(data.data, 0);
            }else {
                homePagelist("", 0);
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
/*表格*/
var dataSource = new Array();
//table的数据源
var table;
dataSource = [];
function homePagelist(data, index){
    dataSource.splice(0,dataSource.length);//清空数组
    var datashu =data.startRow+1;
    $.each(data.data, function (i, field) {

        var datashus = datashu++
        var rowData = new Array();
        rowData.push(datashus);
        rowData.push(field.websiteName);
        rowData.push(field.websiteUrl);
        rowData.push(field.updateTime);
        rowData.push(field.createUser);
        rowData.push(field.id);
        dataSource.push(rowData);

    });

    initData(dataSource);
    function initData(dataSource) {
        var dttable = $('#homePagetable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#homePagetable").DataTable({
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": false,
            "destroy": false,
            "bAutoWidth": false,
            "bLengthChange": false,
            "aLengthMenu":[10,20,30],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
                "sProcessing": "<img src='./loading.gif' />"
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[0]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[1]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 1
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[2]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 2
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[3]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 3
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[4]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 4
                },

                {
                    "render": function (data, type, row, meta) {
                        var  val = '<a onclick="homePagedetails(\'设置详情\',\'settingDetails.html\',\''+row[5]+'\')">设置</a>';
                        return val;
                    },
                    "targets":5
                },

            ]
        });
    };
}
/*跳转*/
function homePagedetails(title,url,data){
    sessionStorage.setItem("homePageId",data);
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
    